// pages/settingFullRule/settingFullRule.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    numArr: [1,2,3],
    numIndex: 0,
    gradArray: [{
        money: '',
        ids: [],
        id: ''
    }, {
            money: '',
            ids: [],
            id: ''
    }, {
            money: '',
            ids: [],
            id: ''
    }]
  },
  create(){
      let data = this.data
    let obj = JSON.parse(JSON.stringify(data.gradArray))
    obj.splice(+data.numIndex + 1)
    console.log(obj)
    let result = obj.some(info => {
        if (Object.values(info).filter(val => String(val).trim() === '').length) {
            return true
        }
    })
    if(result){
        wx.showModal({
            title: '提示',
            content: '尚有信息未填写',
            showCancel: false
        })
        return
    }
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setFullRule({
        numIndex: data.numIndex,
        rule: data.gradArray
    })
    wx.navigateBack({
        
    })
  },
  setCouponPool({ couponPoolIds, couponPoolId, extra }) {
      this.data.gradArray[extra].ids = couponPoolIds 
      this.data.gradArray[extra].id = couponPoolId
      this.setData({
          gradArray: this.data.gradArray
      })
  },
  iM(e){
      const index = e.currentTarget.dataset.index
    let value = e.detail.value
    this.data.gradArray[index].money = value
    this.setData({
        gradArray: this.data.gradArray
    })
  },
  navTicket(e){
      const index = e.currentTarget.dataset.index 
      let ids = this.data.gradArray[index].ids
    wx.navigateTo({
        url: `/pages/ticketsChoose/ticketsChoose?type=choose&couponPoolIds=${JSON.stringify(ids)}&extra=${index}`,
    })
  },
  
    numPickerChange(e){
        this.setData({
            numIndex: e.detail.value
        })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options)
      let obj = JSON.parse(options.obj)
    if(obj.numIndex){
        this.setData({
            numIndex: obj.numIndex
        })
    }
    if(obj.rule){
        this.setData({
            gradArray: Object.assign(this.data.gradArray, obj.rule)
        })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})